package game.editer;

import hx.events.MouseEvent;
import hx.display.Quad;
import game.editer.ui.Config;
import hx.display.Label;
import hx.display.Image;
import hx.display.BitmapData;
import hx.display.Box;

/**
 * 精灵帧对象
 */
class SpriteFrame extends Box {
	public var selected:Quad;

	public var data:SpriteFrameData;

	public function new(data:SpriteFrameData, bitmapData:BitmapData):Void {
		super();

		this.data = data;

		selected = new Quad(bitmapData.rect.width, bitmapData.rect.height, 0x848484);
		this.addChild(selected);
		selected.alpha = 0;

		this.width = bitmapData.rect.width;
		this.height = bitmapData.rect.height + 32;
		var image = new Image(bitmapData);
		this.addChild(image);
		if (bitmapData.frameRect != null) {
			image.x = bitmapData.frameRect.x;
			image.y = bitmapData.frameRect.y;
		}
		image.mouseEnabled = false;

		this.mouseChildren = false;

		var label = new Label(Std.string(data.index + 1), Config.COMMON_TEXT_FORMAT);
		this.addChild(label);
		label.horizontalAlign = CENTER;
		label.width = this.width;
		label.height = 32;
		label.y = this.height - 32;

		this.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent) {
			selected.alpha = 1;
		});
		this.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent) {
			selected.alpha = 0;
		});
	}
}

typedef SpriteFrameData = {
	var index:Int;
	var name:String;
}
